controls.TextArea = function(options, referenceNode, store) {
    var thisClass = controls.TextArea;
    thisClass.prototype.__proto__.constructor.apply(this, arguments);
}
extend(controls.TextArea, controls.GeneralInput);

controls.TextArea.prototype.initialize = function(load) {
    var html = '<textarea id=' + this.options.id + ' class="textArea" />';
    this.referenceNode.insertAdjacentHTML('afterEnd', html);
    this.applyProperty(this.options);

    this.bindTextarea(this.domElement)
}
controls.TextArea.Shadow = document.createElement("div");
controls.TextArea.Shadow.style["visibility"] = "hidden";
controls.TextArea.Shadow.Host = null;
document.body.insertBefore(controls.TextArea.Shadow, document.body.childNodes[0]);

//绑定编辑区域，使其能随文本变化而变大变小。宽度的最大和最小限制根据css来判断。
controls.TextArea.prototype.bindTextarea = function(el) {
    el.addEventListener("input", function(event) {
        var shadow = controls.TextArea.Shadow;
        if (shadow.Host != el) {
            shadow.Host = el
            var currStyle = el.ownerDocument.defaultView.getComputedStyle(el, null);
            ////如果没有限制，默认宽度变化为【100，300】
            var max = parseInt(currStyle["max-width"]) || 300;
            var min = parseInt(currStyle["min-width"]) || 100;
            //如果在td内，计算td内的空间做为最大宽度
            if (el.parentElement.querySelector("td #" + this.options.id)) {
                var innerWidth;
                var td = el.parentElement;
                while (td.tagName != "td") td = td.parentElement;
                var style = getComputedStyle(td);
                if (style.boxSizing == "content-box") {
                    innerWidth = parseInt(style.width);
                } else {
                    innerWidth = parseInt(style.width) -
                        parseInt(style.borderLeftWidth) - parseInt(style.borderRightWidth) -
                        parseInt(style.paddingLeft) - parseInt(style.paddingRight);
                }
            }
            max = Math.min(max, innerWidth);
            for (var i = 0; i < currStyle.length; i++) {
                shadow.style[currStyle[i]] = currStyle[currStyle[i]];
            }
            shadow.style["max-width"] = max + "px";
            shadow.style["min-width"] = min + "px";
            shadow.style["display"] = "inline-block";
            shadow.style["visibility"] = "hidden";
            shadow.style["z-index"] = "-1";
            shadow.style["margin-left"] = "-100%";
            shadow.style["height"] = "auto";
            shadow.style["width"] = "auto";
            shadow.style["position"] = "absolute";
            shadow.style["word-break"] = "break-all";
            el.style["word-break"] = "break-all";
        }
        shadow.innerHTML = el.value.replace(/\n/gm, '<br>').replace(/\s/gm, '&nbsp;') || 'a';
        var ttStyle = shadow.getBoundingClientRect();
        el.style.width = ttStyle["width"];
        el.style.height = ttStyle["height"];
    });
};